package edu.utd.text.game.designer.commands;

import java.util.Scanner;

import edu.utd.text.game.designer.controller.DesignerController;
import edu.utd.text.game.domain.areas.Room;
import edu.utd.text.game.domain.exceptions.GameObjectNotFoundException;
import edu.utd.text.game.domain.item.GameItem;

public class DeleteGameItemCommand implements DesignerCommand {

	public DeleteGameItemCommand() {  }
	
	public String execute() throws Exception {
		//get Room name
		Scanner scanner = new Scanner(System.in);
		System.out.println("Room to delete item from: ");
		String roomName = scanner.nextLine().trim();
		Room room = DesignerController.INSTANCE.getGameMap().getRoomByName(roomName);
		if (null == room) 
			{ return "Cannot find room \"" + roomName + "\" in the game map."; }
		
		//get GameItem name
		System.out.println("Game item name: ");
		String itemName = scanner.nextLine().trim();
		
		//Delete GameItem from room
		try {
			
			GameItem itemToDelete = room.retrieveGameItemByName(itemName);
			boolean successful = room.removeObjectFromRoom(itemToDelete);
			if (successful) {
				return "Successfully removed game item + \"" + itemToDelete.getName()
					+ "\" from room \"" + room.getRoomName() + "\".";
				
			} 
			return "FAILED to remove game item: \"" 
				+ itemToDelete.getName() + "\" from the room: \""
				+ room.getRoomName() + "\".  Not sure why...";
			
		} catch (GameObjectNotFoundException gonf) {
			return "No game item named \"" + itemName 
				+ "\" exists in the room: \"" + room.getRoomName() + "\"."; 
		}
	}

}
